package com.example.broad.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.util.Log;

import com.example.broad.util.DateUtil;
import com.example.broad.util.NetworkUtil;

/**
 * @author: snjgm
 * data: 2022/7/25
 * description: 网络变更广播接收器
 */
public class NetworkChangeReceiver extends BroadcastReceiver {

    private String text;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            NetworkInfo networkInfo = intent.getParcelableExtra("networkInfo");
            String networkClass = NetworkUtil.getNetworkClass(networkInfo.getSubtype());
            text = String.format("收到一个网络变更广播,网络大类为%s," + "网络小类为%s,网络制式为%s,网络状态为%s",
                    networkInfo.getTypeName(),networkInfo.getSubtypeName(), NetworkUtil.getNetworkClass(networkInfo.getSubtype()),
                    networkInfo.getState().toString());
        }
        Log.d("TAG", text);
    }
}
